//
//  BaseViewController.m
//  Account
//
//  Created by wanmeizty on 2016/11/29.
//  Copyright © 2016年 wanmeizty. All rights reserved.
//

#import "BaseViewController.h"

#import "UIColor+RGB.h"

#import "ViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithRGB:0xf4f4f4];
//
//    UIImage *image = [self imageWithColor:[UIColor whiteColor]];
//    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
//    [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
//    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
//    //    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
//    [self.navigationController.navigationBar setTintColor:[UIColor colorWithRGB:0xfcfcfc]];
//    //    [self.navigationController.navigationBar setTranslucent:YES];
//    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor colorWithRGB:0x333333],
//                                                                    NSFontAttributeName : [UIFont boldSystemFontOfSize:17.0f]};
    
    if([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        self.edgesForExtendedLayout= UIRectEdgeNone;
    }

    
    self.rootScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    self.rootScrollView.backgroundColor = [UIColor whiteColor]; //[UIColor colorWithRed:176/255.0 green:205/255.0 blue:234/255.0 alpha:1];
    self.rootScrollView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.rootScrollView.layer.borderWidth = 0.5;
    [self.view addSubview:self.rootScrollView];
    
    // Do any additional setup after loading the view.
}

- (void)enabledBackButton {
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.backgroundColor = [UIColor clearColor];
    self.backBtn = backBtn;
    [backBtn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateHighlighted];
    backBtn.frame = CGRectMake(15, 0, 8, 15); //[XMScreenAdaptation adapterRectByWidth:(CGRect){15, 0, 8, 15}];
    //    [backBtn setEnlargeEdgeWithTop:4 right:4 bottom:4 left:4];
    [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    //    typeof(self) __weak weakSelf = self;
    //    [backBtn addAction:^(UIButton *btn) {
    //        [weakSelf backButtonTapped];
    //    }];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    //    self.tempF = self.navigationItem.leftBarButtonItem.customView.frame;
}

- (void)backClick {
    [self.navigationController popViewControllerAnimated:YES];
}

- (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0, 0, 1, 1);
    UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
    [color setFill];
    UIRectFill(rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
    
    if ([self isKindOfClass:[ViewController class]]) {
        
    }else{
        
        [self enabledBackButton];
        
    }
   
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
